package com.fuyao.cloud.personnel.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.excel.annotation.ResponseExcel;
import com.fuyao.cloud.common.log.annotation.SysLog;
import com.fuyao.cloud.personnel.api.entity.RecognitionRecords;
import com.fuyao.cloud.personnel.service.RecognitionRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 表彰记录表
 *
 * @author pigx code generator
 * @date 2022-06-20 11:19:21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/recognition/records" )
@Api(value = "recognitionrecords", tags = "表彰记录表管理")
public class RecognitionRecordsController {

    private final RecognitionRecordsService recognitionRecordsService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param recognitionRecords 表彰记录表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('recognition_records_view')" )
    public R getRecognitionRecordsPage(Page page, RecognitionRecords recognitionRecords) {
        return R.ok(recognitionRecordsService.page(page, Wrappers.query(recognitionRecords)));
    }


    /**
     * 通过id查询表彰记录表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('recognition_records_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(recognitionRecordsService.getById(id));
    }

    /**
     * 新增表彰记录表
     * @param recognitionRecords 表彰记录表
     * @return R
     */
    @ApiOperation(value = "新增表彰记录表", notes = "新增表彰记录表")
    @SysLog("新增表彰记录表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('recognition_records_add')" )
    public R save(@RequestBody RecognitionRecords recognitionRecords) {
        return R.ok(recognitionRecordsService.save(recognitionRecords));
    }

    /**
     * 修改表彰记录表
     * @param recognitionRecords 表彰记录表
     * @return R
     */
    @ApiOperation(value = "修改表彰记录表", notes = "修改表彰记录表")
    @SysLog("修改表彰记录表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('recognition_records_edit')" )
    public R updateById(@RequestBody RecognitionRecords recognitionRecords) {
        return R.ok(recognitionRecordsService.updateById(recognitionRecords));
    }

    /**
     * 通过id删除表彰记录表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除表彰记录表", notes = "通过id删除表彰记录表")
    @SysLog("通过id删除表彰记录表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('recognition_records_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(recognitionRecordsService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param recognitionRecords 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('recognition_records_export')" )
    public List<RecognitionRecords> export(RecognitionRecords recognitionRecords) {
        return recognitionRecordsService.list(Wrappers.query(recognitionRecords));
    }
}

